from rest_framework.generics import ListAPIView
from rest_framework.permissions import IsAdminUser
from rest_framework.viewsets import ModelViewSet

from goods.models import SKUImage, SKU
from meiduo_admin.serializers.skus import SKUImageSerializer, SKUSimpleSerializer


# 定制图片数据获取的视图集
class SKUImageViewSet(ModelViewSet):
    # 1 保证管理员登录
    permission_classes = [IsAdminUser]
    # 2 路由规则名称的定制
    lookup_value_regex = '\d+'
    # 3 指定序列化类名
    serializer_class = SKUImageSerializer
    # 4 指定数据的获取
    queryset = SKUImage.objects.all()

# 查看图片的基本信息
class SKUSimpleView(ListAPIView):
    # 1 只有管理员才能查看
    permission_classes = [IsAdminUser]
    # 2 定制序列化器类
    serializer_class = SKUSimpleSerializer
    # 3 定制数据查询集
    queryset = SKU.objects.all()
    # 4 关闭默认的分页功能
    pagination_class = None
